﻿namespace CatchBall
{
    using System;

    public class Gun
    {
        private static Random randomGenerator = new Random();

        public Gun()
        {
            this.Row = 3;
        }

        public int Row { get; private set; }

        public void MoveWeapon()
        {
            // remember the old position for clearance purposes
            int rowToClear = this.Row;

            // move the weapon
            this.Row = randomGenerator.Next(19);
            if (this.Row % 2 == 1)
            {
                this.Row--;
            }

            this.ClearPreviousWeapon(rowToClear);
            this.VisualizeWeapon();
        }

        // prints the weapon
        public void VisualizeWeapon()
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.SetCursorPosition(61, this.Row);
            Console.Write(" ____________");
            Console.SetCursorPosition(61, this.Row + 1);
            Console.Write("|_____   _   |");
            Console.SetCursorPosition(61, this.Row + 2);
            Console.Write("      | | \\  |");
            Console.SetCursorPosition(61, this.Row + 3);
            Console.Write("      |_|  |_|");
            Console.ResetColor();

            MainCatchBall.PlayAudioFile("../../External Files/gun.wav");
        }

        // deletes the weapon from the previous position
        private void ClearPreviousWeapon(int row)
        {
            Console.SetCursorPosition(61, row);
            Console.Write("              ");
            Console.SetCursorPosition(61, row + 1);
            Console.Write("              ");
            Console.SetCursorPosition(61, row + 2);
            Console.Write("              ");
            Console.SetCursorPosition(61, row + 3);
            Console.Write("              ");
        }
    }
}
